package com.study_online.mapper;/*
    张昊（java文件）
 
*/

import com.study_online.domain.CommentB;
import com.study_online.domain.CommentBelonging;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface CommentMapper {
    //根据视频id查看该视频下的所有评论
    @Select("select * from comment where vido_id=#{vido_id}")
    List<CommentB> findById(@Param("vido_id") int vido_id);

    //添加评论
    @Insert("insert into comment value(null,#{vido_id},#{user_id},#{text},null,#{addtime})")
    int addComment(@Param("vido_id") int vido_id, @Param("user_id") int user_id, @Param("text") String text, @Param("addtime") String addtime);

    //删除评论
    @Delete("delete from comment where comment_id=#{commentId} and user_id=#{userId}")
    int deleteComment(@Param("commentId") int commentId,@Param("userId") int userId);

    //添加评论
    @Insert("insert into comment_belonging value(null,#{commentId},#{userId},#{text},#{addTime},null)")
    int addCommentB(@Param("commentId") int commentId,@Param("userId") int userId,@Param("text") String text,@Param("addTime") String addTime);


    //根据评论id查找
    @Select("select * from comment_belonging where comment_id=#{commentId}")
    List<CommentBelonging> findCommentBelonging(@Param("commentId") int commentId);

    //根据评论id删除
    @Delete("delete from comment_belonging where comment_id=#{commentId}")
    int deleteCommentB(@Param("commentId") int commentId);

    //根据回复id删除
    @Delete("delete from comment_belonging where comment_b_id=#{commentBId} and user_id=#{userId}")
    int deleteCommentBId(@Param("commentBId") int commentBId,@Param("userId") int userId);
}
